package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.NoteFormDTO;
import com.tianji.learning.domain.query.NotePageQuery;
import com.tianji.learning.domain.vo.NoteVO;
import com.tianji.learning.service.ILearningNoteService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学习笔记 前端控制器
 * </p>
 *
 * @author 虎哥
 * @since 2025-11-08
 */
@RestController
@RequestMapping("/notes")
@RequiredArgsConstructor
public class LearningNoteController {
    
    private final ILearningNoteService noteService;

    /**
     * 新增笔记
     * @param noteDTO
     */
    @ApiOperation("新增笔记")
    @PostMapping
    public void saveNote(@Valid @RequestBody NoteFormDTO noteDTO){
        noteService.saveNote(noteDTO);
    }

    @ApiOperation("分页查询全部笔记")
    @GetMapping("/portal")
    public PageDTO<NoteVO> queryAllPage(NotePageQuery query){
        if (query.getOnlyMine() == null) {
            query.setOnlyMine(false);
        }
        return noteService.queryAllNotePage(query);
    }
    
    @ApiOperation("分页查询我的笔记")
    @GetMapping("/me")
    public PageDTO<NoteVO> queryMyPage(NotePageQuery query){
        query.setOnlyMine(true);
        return noteService.queryAllNotePage(query);
    }
}